﻿<%@ WebHandler Language="C#" Class="ProductType" %>

using System;
using System.Web;
using System.Text;
using System.Web.SessionState;
using Newtonsoft.Json.Converters;
using DB.DataService;
using System.Data;

public class ProductType : IHttpHandler, IReadOnlySessionState
{
    
    public void ProcessRequest (HttpContext context) {
        try
        {
            string login = context.Request.Cookies["logout"].Value;
            if (!string.IsNullOrEmpty(login))
            {
                
                ProductsService pr = new ProductsService();
                DataSet ds = new DataSet();
                ds = pr.GetAllProductType();
                int total = 0;
                string strtable = "";
                if (ds.Tables[0].Rows.Count > 0)
                {
                    total = Convert.ToInt32(ds.Tables[0].Rows.Count);
                    strtable = Newtonsoft.Json.JsonConvert.SerializeObject(ds.Tables[0]);
                }

                context.Response.ContentType = "text/plain";
                StringBuilder datajson = new StringBuilder();
                datajson.Append("{ ");
                datajson.Append("total: ");
                datajson.Append(total);
                datajson.Append(",");
                datajson.Append("\"rows\":");
                datajson.Append(strtable);
                datajson.Append("}");
                context.Response.Write(Newtonsoft.Json.JsonConvert.DeserializeObject(datajson.ToString()));
            }
        }
        catch (Exception)
        {

            throw;
        }
    }
 
    public bool IsReusable {
        get {
            return false;
        }
    }

}